﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditCourseData.aspx.cs" Inherits="Staff_EditCourseData" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">



        .style1
        {
            font-family: 微軟正黑體;
            font-size: xx-large;
            text-align: center;
        }
        .style2
        {
            text-align: center;
        }
        .style3
        {
            width: 80%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style2">
    
        <span class="style1">編輯開課資料</span><br />
        <br />
        <table align="center" class="style3">
            <tr>
                <td colspan="2">
                    請輸入欲編輯課程之編號：<asp:TextBox ID="TextBox2" runat="server" ValidationGroup="phone"></asp:TextBox>
&nbsp;<asp:Button ID="Button1" runat="server" Text="查詢" ValidationGroup="phone" />
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                        ControlToValidate="TextBox2" ErrorMessage="RegularExpressionValidator" 
                        ValidationExpression="^[0-9]{1,20}$" style="color: #FF0000" 
                        ValidationGroup="phone">僅限數字</asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                            CellPadding="4" DataKeyNames="CourseId" DataSourceID="SqlDataSource1" 
                            DefaultMode="Edit" ForeColor="#333333" GridLines="None" Height="50px" 
                            style="text-align: center" Width="444px">
                            <AlternatingRowStyle BackColor="White" />
                            <CommandRowStyle BackColor="#FFFFC0" Font-Bold="True" />
                            <FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
                            <Fields>
                                <asp:BoundField DataField="CourseId" HeaderText="當年課程編號" ReadOnly="True" 
                                    SortExpression="CourseId" />
                                <asp:BoundField DataField="CourseName" HeaderText="課程名稱" 
                                    SortExpression="CourseName" />
                                <asp:BoundField DataField="Year" HeaderText="開設年分" SortExpression="Year" />
                                <asp:BoundField DataField="Semester" HeaderText="上下學期" 
                                    SortExpression="Semester" />
                                <asp:TemplateField HeaderText="介紹" SortExpression="Intro">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Height="65px" 
                                            Text='<%# Bind("Intro") %>' TextMode="MultiLine" Width="223px"></asp:TextBox>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Intro") %>'></asp:TextBox>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Intro") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:CheckBoxField DataField="IsLimitNum" HeaderText="是否限制人數" 
                                    SortExpression="IsLimitNum" />
                                <asp:BoundField DataField="LimitNum" HeaderText="人數上限" 
                                    SortExpression="LimitNum" />
                                <asp:BoundField DataField="Point" HeaderText="學分" 
                                    SortExpression="Point" />
                                <asp:BoundField DataField="Length" HeaderText="單周授課時數" 
                                    SortExpression="Length" />
                                <asp:CommandField ButtonType="Button" ShowInsertButton="True" />
                                <asp:CommandField ButtonType="Button" ShowEditButton="True" />
                            </Fields>
                            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                        </asp:DetailsView>
                    </td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
            DeleteCommand="DELETE FROM [Course] WHERE [CourseId] = @CourseId" 
            InsertCommand="INSERT INTO [Course] ([CourseId], [CourseName], [Year], [Semester], [Intro], [IsLimitNum], [LimitNum], [Point], [Length]) VALUES (@CourseId, @CourseName, @Year, @Semester, @Intro, @IsLimitNum, @LimitNum, @Point, @Length)" 
            SelectCommand="SELECT * FROM [Course] WHERE ([CourseId] = @CourseId)" 
            
            UpdateCommand="UPDATE [Course] SET [CourseName] = @CourseName, [Year] = @Year, [Semester] = @Semester, [Intro] = @Intro, [IsLimitNum] = @IsLimitNum, [LimitNum] = @LimitNum, [Point] = @Point, [Length] = @Length WHERE [CourseId] = @CourseId">
            <DeleteParameters>
                <asp:Parameter Name="CourseId" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="CourseId" Type="Int32" />
                <asp:Parameter Name="CourseName" Type="String" />
                <asp:Parameter Name="Year" Type="String" />
                <asp:Parameter Name="Semester" Type="Int32" />
                <asp:Parameter Name="Intro" Type="String" />
                <asp:Parameter Name="IsLimitNum" Type="Boolean" />
                <asp:Parameter Name="LimitNum" Type="Int32" />
                <asp:Parameter Name="Point" Type="Int32" />
                <asp:Parameter Name="Length" Type="Int32" />
            </InsertParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBox2" Name="CourseId" PropertyName="Text" 
                    Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="CourseName" Type="String" />
                <asp:Parameter Name="Year" Type="String" />
                <asp:Parameter Name="Semester" Type="Int32" />
                <asp:Parameter Name="Intro" Type="String" />
                <asp:Parameter Name="IsLimitNum" Type="Boolean" />
                <asp:Parameter Name="LimitNum" Type="Int32" />
                <asp:Parameter Name="Point" Type="Int32" />
                <asp:Parameter Name="Length" Type="Int32" />
                <asp:Parameter Name="CourseId" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    
        <br />
    
    </div>
    </form>
</body>
</html>
